package tech.aistar.design.factory.version07;

import tech.aistar.day06.extend.Dog;
import tech.aistar.util.prop.PropUtil;

/**
 * 本类用来演示: 反射工厂
 *
 * @author: success
 * @date: 2021/3/16 4:48 下午
 */
public class BeanFactory {

    public static <T>T getInstance(String className){
        //Object obj = null;
        T t = null;
        //1. 获取class实例
        try {
            Class<?> c = Class.forName(className);
            t = (T) c.newInstance();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InstantiationException e) {
            e.printStackTrace();
        }
        return t;
    }
}

class TestBean{
    public static void main(String[] args) {
        //Dog dog = BeanFactory.getInstance("tech.aistar.day06.extend.Dog");
        IUserDao userDao = BeanFactory.getInstance(PropUtil.getValue("userdao"));
    }
}
